package com.coolbi.onsupai.core.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.onsupai.core.dao.CouponDao;
import com.coolbi.onsupai.core.entity.Coupon;
import com.coolbi.onsupai.core.mapper.CouponMapper;

public class CouponDaoImpl implements CouponDao {
	@Autowired
	private CouponMapper couponMapper;
	public void setCouponMapper(CouponMapper couponMapper) {
		this.couponMapper = couponMapper;
	}

	@Override
	public Coupon save(Coupon obj) {
		couponMapper.save(obj);
		return obj;
	}

	@Override
	public int delete(long id) {
		return couponMapper.delete(id);
	}

	@Override
	public int update(Coupon obj) {
		return couponMapper.update(obj);
	}

	@Override
	public Coupon get(long id) {
		return couponMapper.get(id);
	}

	@Override
	public List<Coupon> list() {
		return couponMapper.list();
	}

	@Override
	public List<Coupon> listByPage(int offset, int limit) {
		Map<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("offset", offset);
		parameter.put("limit",limit);
		return couponMapper.listByPage(parameter);
	}

	@Override
	public List<Coupon> find(Map<String, Object> parameter) {
		return couponMapper.listByParameter(parameter);
	}

	@Override
	public List<Coupon> findByPage(Map<String, Object> parameter, int offset,
			int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return couponMapper.listByParameterPage(parameter);
	}

	@Override
	public List<Coupon> search(Map<String, Object> parameter, int offset,
			int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return couponMapper.search(parameter);
	}

	@Override
	public int count() {
		return couponMapper.count();
	}

	@Override
	public int countByKeyWord(Map<String, Object> parameter) {
		return couponMapper.countByKeyWord(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return couponMapper.countByParameter(parameter);
	}

	@Override
	public Coupon findByCouponNo(String couponNo, Long customerId, Integer status) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("couponNo", couponNo);
		parameter.put("customerId", customerId);
		parameter.put("status", status);
		return couponMapper.findByCouponNo(parameter);
	}

	@Override
	public int updateCouponStatus(String couponNo, Long customerId, Integer status) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("couponNo", couponNo);
		parameter.put("customerId", customerId);
		parameter.put("status", status);
		return couponMapper.updateCouponStatus(parameter);
	}
}
